package cn.tedu.clyback.permission.controller;

import cn.tedu.clyback.RolePermission.pojo.vo.RolePermissionVO;
import cn.tedu.clyback.base.response.JsonResult;
import cn.tedu.clyback.permission.pojo.dto.PermissionSelectParam;
import cn.tedu.clyback.permission.pojo.entity.Permission;
import cn.tedu.clyback.permission.pojo.vo.PermissionVO;
import cn.tedu.clyback.permission.service.PermissionService;
import cn.tedu.clyback.role.pojo.entity.Role;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @GetMapping("/select")
    public JsonResult getPermission(PermissionSelectParam permissionSelectParam) {
        log.debug("权限查询参数：{}", permissionSelectParam);
        List<PermissionVO> permissionVOList = permissionService.getPermission(permissionSelectParam);
        log.debug("权限查询结果：{}", permissionVOList);
        return JsonResult.ok(permissionVOList);
    }
    @PostMapping("/save")
    public JsonResult savePermission(Permission permission) {
        log.debug("权限查询参数：{}", permission);
        permissionService.savePermission(permission);
        return JsonResult.ok();
    }
    @PostMapping("/delete/{permissionId}")
    public JsonResult deletePermission(@PathVariable Integer permissionId) {
        log.debug("权限id：{}", permissionId);
        permissionService.deletePermission(permissionId);
        return JsonResult.ok();
    }

    @GetMapping("/unselect/{roleId}")
    public JsonResult unserlectPermission(@PathVariable Integer roleId) {
        log.debug("角色id：{}", roleId);
        List<PermissionVO> list=permissionService.unselectPermission(roleId);
        return JsonResult.ok(list);
    }
    @GetMapping("/selectuserrole/{roleId}")
    public JsonResult selectuserroleByRoleId(@PathVariable Integer roleId){
        log.debug("查询拥有该角色权限的用户");
        List<RolePermissionVO> list=permissionService.selectuserroleById(roleId);
        log.debug("{查询拥有该角色权限的用户结果}"+list);
        return JsonResult.ok(list);
    }
}
